package com.wanshi.utils;

import java.lang.reflect.Method;

@SuppressWarnings("all")
public class DatiThread<T> extends Thread{


    //用来记录方法执行结果的
    private T result;

    public T getResult() {
        return result;
    }

    private String name;
    private String method;
    private Object[] objs;

    public DatiThread(String name, String method, Object[] objs){
        this.name = name;
        this.method = method;
        this.objs = objs;
    }

    @Override
    public void run() {

        try{
            //3 反射调方法
            Class<?> c = Class.forName(name);
            // 反射类的方法：
            Method[] ms = c.getMethods();
            for (int i = 0; i < ms.length; i++) {
                String methodName = ms[i].getName();
                if(methodName.equals(method)){
                    result = (T) ms[i].invoke(c.getDeclaredConstructor().newInstance(),objs);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
